<script lang="ts" setup>
import { SwitchButton } from '@element-plus/icons-vue'
const router = useRouter()
const defaultActive = router.currentRoute.value.path
const menu = router.currentRoute.value.matched[0].children
const userStore = useUserStore()
const dictStore = useDictStore()
dictStore.fetchDictionary()
const loginOut = () => {
  userStore.logoutConfirm()
}
</script>
<template>
  <div class="app">
    <header class="header">
      <div class="logo" @click="router.push('/requirementSolution')">
        <img class="logo-img" src="@/assets/images/logo-personalCenter.png" alt="" />
        <span class="logo-text">个人中心</span>
      </div>
      <div class="user-box">
        <div class="user">
          <!-- <img class="user-head" src="" alt="" /> -->
          <p class="user-name">{{ userStore.getUserInfo?.username }}</p>
        </div>
        <div class="logout" @click="loginOut">
          <el-icon class="logout-icon"><SwitchButton /></el-icon>
          <span class="logout-text">退出</span>
        </div>
      </div>
    </header>
    <main class="main">
      <div class="main-left">
        <el-menu class="main-left-menu" :default-active="defaultActive" background-color="#4688f6">
          <el-menu-item
            :index="item.path"
            v-for="item in menu"
            :key="item.path"
            @click="router.push(item.path)"
          >
            <span class="icon" />
            <span class="name">{{ item?.meta?.title }}</span>
          </el-menu-item>
        </el-menu>
      </div>
      <div class="main-right">
        <div class="crumbs">
          <el-breadcrumb separator="/">
            <el-breadcrumb-item>产业计量云（长三角）后台管理系统</el-breadcrumb-item>
            <el-breadcrumb-item>{{ router.currentRoute?.value?.meta?.title }}</el-breadcrumb-item>
          </el-breadcrumb>
        </div>
        <div class="main-content">
          <router-view />
        </div>
      </div>
    </main>
  </div>
</template>
<style lang="scss" scoped>
.app {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}
.header {
  width: 100%;
  height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #4688f6;
  .logo {
    margin-left: 22px;
    display: flex;
    align-items: center;
    cursor: pointer;
    .logo-img {
      width: 55px;
      height: 40px;
    }
    .logo-text {
      font-size: 24px;
      color: #ffffff;
      line-height: 22px;
      margin-left: 15px;
    }
  }
  .user-box {
    margin-right: 40px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    .user {
      display: flex;
      align-items: center;
      .user-head {
        width: 24px;
        height: 24px;
        border-radius: 50%;
        margin-right: 8px;
      }
      .user-name {
        font-size: 14px;
        color: #ffffff;
        line-height: 22px;
      }
    }
    .logout {
      margin-left: 22px;
      display: flex;
      align-items: center;
      cursor: pointer;
      .logout-icon {
        font-size: 14px;
        margin-right: 10px;
        color: #fff;
      }
      .logout-text {
        font-size: 14px;
        color: #ffffff;
        line-height: 22px;
      }
    }
  }
}

.main {
  width: 100%;
  height: calc(100vh - 60px);
  display: flex;
  .main-left {
    width: 280px;
    height: 100%;
    background: #4688f6;
    padding: 0 10px;
    :deep(.el-menu) {
      border: none;
    }
    .main-left-menu {
      --el-menu-item-height: 48px;

      :deep(.el-menu-item) {
        font-size: 14px;
        color: #ffffff;
        border-radius: 8px;
        .icon {
          width: 16px;
          height: 16px;
          background: #fff;
          opacity: 0.5;
          margin-right: 12px;
        }
        &.is-active {
          background: #fff;
          color: #4688f6;

          .icon {
            background: #4688f6;
          }
        }
      }
    }
  }
  .main-right {
    width: calc(100% - 280px);
    height: 100%;
    .crumbs {
      height: 38px;
      display: flex;
      align-items: center;
      padding: 0 24px;
      :deep(.el-breadcrumb__inner) {
        font-size: 14px;
        color: rgba(0, 0, 0, 0.45);
      }
    }
    .main-content {
      background: #f2f2f2;
      padding: 20px;
      height: calc(100% - 38px);
    }
  }
}
</style>
